package com.example.test_animator

import android.os.Bundle
import android.util.Log
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.opensource.svgaplayer.SVGACallback
import com.opensource.svgaplayer.SVGADrawable
import com.opensource.svgaplayer.SVGAImageView
import com.opensource.svgaplayer.SVGAParser
import com.opensource.svgaplayer.SVGAPlayer
import com.opensource.svgaplayer.SVGAVideoEntity
import java.net.URL

class MainActivity2 : AppCompatActivity() {
    companion object {
        const val TAG = "MainActivity2"
    }
    private lateinit var svgImageView: SVGAImageView
    private lateinit var parser: SVGAParser
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main2)
        svgImageView = findViewById(R.id.svgaview)

        parser = SVGAParser.shareParser() //解析器
        parser.init(this) //初始化
//        parser.decodeFromAssets("car.svga", object :SVGAParser.ParseCompletion{
//            override fun onComplete(videoItem: SVGAVideoEntity) {
//                Log.d(TAG, "onComplete: ")
//                val svgaDrawable = SVGADrawable(videoItem)
//                svgImageView.setImageDrawable(svgaDrawable)
//                svgImageView.startAnimation()
//            }
//
//            override fun onError() {
//                Log.d(TAG, "onError: ")
//            }
//        })
        parser.decodeFromURL(URL("http://10.161.9.80:7015/gift/download/car"),object :SVGAParser.ParseCompletion{
            override fun onComplete(videoItem: SVGAVideoEntity) {
                Log.d(TAG, "onComplete: ")
                val svgaDrawable = SVGADrawable(videoItem)
                svgImageView.setImageDrawable(svgaDrawable)
                svgImageView.startAnimation()
            }

            override fun onError() {
                Log.d(TAG, "onError: ")
            }

        })

        svgImageView.callback = object :SVGACallback{
            override fun onFinished() {
                Log.d(TAG, "onFinished: ")
            }

            override fun onPause() {
                Log.d(TAG, "onPause: ")
            }

            override fun onRepeat() {
                Log.d(TAG, "onRepeat: ")
            }

            override fun onStep(frame: Int, percentage: Double) {
                Log.d(TAG, "onStep: ")
            }

        }


    }
}